import json

from datetime import datetime


class DatetimeEncoder(json.JSONEncoder):
	def default(self, obj):
		if isinstance(obj, datetime):
			return obj.strftime('%Y-%m-%d %H:%M:%S')
		else:
			return json.JSONEncoder.default(self, obj)


class DatetimeDecoder(json.JSONDecoder):
	def __init__(self):
		super().__init__(object_hook=self.object_hook)
	
	def object_hook(self, dct):
		for key, value in dct.items():
			if isinstance(value, str):
				try:
					# 尝试解析日期时间格式
					dct[key] = datetime.strptime(value, '%Y-%m-%d %H:%M:%S')
				except (ValueError, TypeError):
					pass
		return dct
			
		
content = {
	"name": "张三",
	"age": 18,
	"height": 1.8,
	"hobby": ["看电影", "看小说", "看游戏"],
	"address": {
		"province": "北京",
		"city": "北京",
		"street": "北京街"
	},
	"is_married": True,
	"is_single": False,
	"score": None,
	"total_score2": (100, 90, 80),
	'now' : datetime.now()
}

r = json.dumps(content, ensure_ascii=False,cls=DatetimeEncoder)
print(r)

r1 = json.loads(r,cls=DatetimeDecoder)
print(r1,type(r1['now']))